<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>数字能量分析系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="趣味数字能量分析，测测你的生活节奏！">
    <style>
        :root {
            --primary: #2c3e50;
            --secondary: #3498db;
            --light: #f8f9fa;
            --dark: #2c3e50;
        }
        body {
            font-family: 'Helvetica Neue', Arial, sans-serif;
            line-height: 1.6;
            background: #f8f9fa;
            max-width: 1400px;
            margin: 3rem auto;
            padding: 0 2rem;
            display: flex;
            flex-wrap: wrap;
            gap: 3rem;
        }
        .analysis-section, .history-section {
            flex: 1;
            max-width: 600px;
            min-width: 500px;
        }
        .analysis-card, .history-card {
            background: white;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
            margin-bottom: 3rem;
            padding: 2.5rem;
        }
        h2 {
            color: var(--primary);
            font-weight: 600;
            margin-bottom: 2rem;
            position: relative;
            padding-left: 1.2rem;
            font-size: 1.5rem;
        }
        h2::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 5px;
            height: 28px;
            background: var(--secondary);
        }
        .input-group {
            margin-bottom: 1.8rem;
        }
        label {
            display: block;
            color: #666;
            font-size: 1rem;
            margin-bottom: 0.6rem;
        }
        input, select {
            width: 100%;
            padding: 1rem;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 1rem;
            transition: border-color 0.3s;
        }
        button {
            background: var(--secondary);
            color: white;
            padding: 1.2rem;
            border: none;
            border-radius: 8px;
            width: 100%;
            font-size: 1.1rem;
            cursor: pointer;
            transition: opacity 0.3s;
        }
        button:hover {
            opacity: 0.9;
        }
        .result-box {
            margin-top: 1.8rem;
            padding: 1.8rem;
            background: var(--light);
            border-radius: 8px;
            display: none;
        }
        .score {
            font-size: 1.8rem;
            font-weight: 700;
            margin-bottom: 0.8rem;
        }
        .blue { color: #3498db; }
        .purple { color: #9b59b6; }
        .orange { color: #e67e22; }
        .analysis-tag {
            font-size: 1.2rem;
            font-weight: 600;
        }
        .red { color: #e74c3c; }
        table {
            width: 100%;
            border-collapse: collapse;
            font-size: 1rem;
        }
        th, td {
            padding: 1rem 1.2rem;
            border: 1px solid #e0e0e0;
            text-align: left;
            line-height: 1.5;
        }
        th {
            background: var(--light);
            color: var(--primary);
            font-weight: 600;
            font-size: 1.1rem;
        }
        td {
            word-break: keep-all;
            white-space: nowrap;
        }
        tr:nth-child(even) {
            background: #f9f9f9;
        }
        tr:hover {
            background: #f0f0f0;
        }
        .history-table-wrapper {
            max-height: 400px;
            overflow-y: auto;
            display: block;
        }
        .history-table-wrapper::-webkit-scrollbar {
            width: 8px;
        }
        .history-table-wrapper::-webkit-scrollbar-track {
            background: #f1f1f1;
            border-radius: 4px;
        }
        .history-table-wrapper::-webkit-scrollbar-thumb {
            background: var(--secondary);
            border-radius: 4px;
        }
        .history-table-wrapper::-webkit-scrollbar-thumb:hover {
            background: #2980b9;
        }
    </style>
</head>
<body>
    <!-- 个人能量分析 -->
    <div class="analysis-section">
        <div class="analysis-card">
            <h2>个人能量</h2>
            <div class="input-group">
                <label>姓名</label>
                <input type="text" id="userName" placeholder="请输入真实姓名">
            </div>
            <div class="input-group">
                <label>出生年月日</label>
                <input type="text" id="birthDate" placeholder="格式：YYYYMMDD" maxlength="8">
            </div>
            <div class="input-group">
                <label>性别</label>
                <select id="gender1">
                    <option value="">请选择</option>
                    <option value="男">男性</option>
                    <option value="女">女性</option>
                </select>
            </div>
            <button onclick="analyzeBirth()">开始测算</button>
            <div id="birthResult" class="result-box">
                <div class="score"></div>
                <div class="analysis-tag"></div>
            </div>
        </div>
    </div>

    <!-- 个人能量历史记录 -->
    <div class="history-section">
        <div class="history-card">
            <h2>历史分析记录</h2>
            <div class="history-table-wrapper">
                <table id="birthHistory">
                    <thead>
                        <tr>
                            <th>输入信息</th>
                            <th>评分</th>
                            <th>分析结果</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
        </div>
    </div>

    <!-- 数字能量分析 -->
    <div class="analysis-section">
        <div class="analysis-card">
            <h2>数字能量</h2>
            <div class="input-group">
                <label>手机号后6位</label>
                <input type="text" id="phone" placeholder="请输入6位数字" maxlength="6">
            </div>
            <div class="input-group">
                <label>性别</label>
                <select id="gender2">
                    <option value="">请选择</option>
                    <option value="男">男性</option>
                    <option value="女">女性</option>
                </select>
            </div>
            <button onclick="analyzePhone()">开始测算</button>
            <div id="phoneResult" class="result-box">
                <div class="score"></div>
                <div class="analysis-tag"></div>
            </div>
        </div>
    </div>

    <!-- 数字能量历史记录 -->
    <div class="history-section">
        <div class="history-card">
            <h2>历史分析记录</h2>
            <div class="history-table-wrapper">
                <table id="phoneHistory">
                    <thead>
                        <tr>
                            <th>输入信息</th>
                            <th>评分</th>
                            <th>分析结果</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
        </div>
    </div>

    <script>
        // 数字分析数据（趣味计算）
        const nineStars = [
            { id: 1, name: "一白", element: "水", luck: "吉" },
            { id: 2, name: "二黑", element: "土", luck: "凶" },
            { id: 3, name: "三碧", element: "木", luck: "中" },
            { id: 4, name: "四绿", element: "木", luck: "吉" },
            { id: 5, name: "五黄", element: "土", luck: "凶" },
            { id: 6, name: "六白", element: "金", luck: "吉" },
            { id: 7, name: "七赤", element: "金", luck: "中" },
            { id: 8, name: "八白", element: "土", luck: "吉" },
            { id: 9, name: "九紫", element: "火", luck: "吉" }
        ];

        // 八卦映射（趣味计算）
        const bagua = ["乾", "兑", "离", "震", "巽", "坎", "艮", "坤"];

        // 六十四卦简表（趣味计算）
        const sixtyFourGua = {
            "1-1": { name: "乾为天", luck: "吉" },
            "6-6": { name: "坎为水", luck: "凶" },
            "2-3": { name: "兑上离下", luck: "中" },
            "4-7": { name: "震上艮下", luck: "吉" }
        };

        // 元素关系（趣味计算）
        const elementRelations = {
            "水": { engenders: "木", restrains: "火" },
            "木": { engenders: "火", restrains: "土" },
            "火": { engenders: "土", restrains: "金" },
            "土": { engenders: "金", restrains: "水" },
            "金": { engenders: "水", restrains: "木" }
        };

        // 计算能量评分
        function calculateEnergy(numbers) {
            const total = numbers.reduce((sum, num) => sum + parseInt(num), 0);
            const starIndex = (total % 9) || 9;
            const mainStar = nineStars.find(star => star.id === starIndex);
            const halfLen = Math.floor(numbers.length / 2);
            const upperGua = numbers.slice(0, halfLen).reduce((sum, num) => sum + parseInt(num), 0) % 8 || 8;
            const lowerGua = numbers.slice(halfLen).reduce((sum, num) => sum + parseInt(num), 0) % 8 || 8;
            const guaKey = `${upperGua}-${lowerGua}`;
            const gua = sixtyFourGua[guaKey] || { name: "默认卦", luck: "中" };
            const currentYearStar = nineStars[(2025 % 9) || 9 - 1];
            let score = 60;
            if (mainStar.luck === "吉") score += 20;
            else if (mainStar.luck === "凶") score -= 10;
            if (gua.luck === "吉") score += 10;
            else if (gua.luck === "凶") score -= 10;
            if (elementRelations[mainStar.element].engenders === currentYearStar.element) score += 5;
            if (elementRelations[mainStar.element].restrains === currentYearStar.element) score -= 5;
            score = Math.min(100, Math.max(10, score));
            return { score };
        }

        // 加载历史记录
        function loadHistory(type) {
            const history = JSON.parse(localStorage.getItem(type) || '[]');
            const tbody = document.querySelector(`#${type}History tbody`);
            tbody.innerHTML = '';
            history.forEach(record => {
                const row = document.createElement('tr');
                row.innerHTML = `
                    <td>${record.input}</td>
                    <td>${record.score}</td>
                    <td>${record.result}</td>
                `;
                tbody.appendChild(row);
            });
        }

        // 保存历史记录
        function saveHistory(type, input, score, result) {
            const history = JSON.parse(localStorage.getItem(type) || '[]');
            history.push({ input, score, result });
            localStorage.setItem(type, JSON.stringify(history));
            loadHistory(type);
        }

        // 个人能量分析
        function analyzeBirth() {
            const birth = document.getElementById('birthDate').value;
            const name = document.getElementById('userName').value.trim();
            const gender = document.getElementById('gender1').value;
            if (!/^\d{8}$/.test(birth)) return alert("请输入8位出生日期（如19900101）");
            if (!name) return alert("请输入姓名");
            if (!gender) return alert("请选择性别");
            const numbers = [...birth].concat(gender === '男' ? 1 : 2);
            const result = calculateEnergy(numbers);
            const inputInfo = `${name}, ${birth}, ${gender}`;
            const levels = ['优质', '良好', '普通'];
            const level = result.score >= 80 ? levels[0] : result.score >= 60 ? levels[1] : levels[2];
            showResult('birthResult', result, levels);
            saveHistory('birth', inputInfo, result.score, level);
        }

        // 数字能量分析
        function analyzePhone() {
            const phone = document.getElementById('phone').value;
            const gender = document.getElementById('gender2').value;
            if (!/^\d{6}$/.test(phone)) return alert("请输入6位手机号后6位");
            if (!gender) return alert("请选择性别");
            const numbers = [...phone].concat(gender === '男' ? 1 : 2);
            const result = calculateEnergy(numbers);
            const inputInfo = `${phone}, ${gender}`;
            const levels = ['可留', '可留可弃', '可弃'];
            const level = result.score >= 80 ? levels[0] : result.score >= 60 ? levels[1] : levels[2];
            showResult('phoneResult', result, levels);
            saveHistory('phone', inputInfo, result.score, level);
        }

        // 结果展示
        function showResult(elementId, result, levels) {
            const container = document.getElementById(elementId);
            const scoreElement = container.querySelector('.score');
            const tagElement = container.querySelector('.analysis-tag');
            scoreElement.className = 'score';
            scoreElement.innerHTML = '';
            tagElement.innerHTML = '';
            let colorClass = 'blue';
            if (result.score > 80) colorClass = 'orange';
            else if (result.score > 60) colorClass = 'purple';
            const levelIndex = result.score >= 80 ? 0 : result.score >= 60 ? 1 : 2;
            scoreElement.classList.add(colorClass);
            scoreElement.innerHTML = `评分：<span>${result.score}</span>分`;
            tagElement.innerHTML = `<div>分析结果：<span class="red">${levels[levelIndex]}</span></div>`;
            container.style.display = 'block';
        }

        // 初始化
        window.onload = function() {
            loadHistory('birth');
            loadHistory('phone');
        };
    </script>
</body>
</html>